//导出（下载） zip 文件
import axios from 'axios'

//导出
//导出
export const handleExportFile = async (
  url,
  type,
  searchData,
  fun
) => {
  axios({
    method: "get",
    url: url,
    data: searchData,
    //重要：相应类型必须为blob
    responseType: "arraybuffer",
  })
    .then((res) => {
      let contentDisposition = decodeURI(res.headers["content-disposition"]);
      let fileRegex = new RegExp("([^(filename=)]+\\." + type + "?)$", "g"); //g;
      let result = contentDisposition.match(fileRegex)[0];
      var link = document.createElement("a");
      //将文件流信息传入
      link.href = window.URL.createObjectURL(new Blob([res.data]));
      link.download = result;
      link.click();
      window.URL.revokeObjectURL(link.href);
      fun && fun();
    })
    .catch((err) => {
      console.log('导出失败')
    });
};